package de.mock.services.http;

import com.fasterxml.jackson.databind.ObjectMapper;
import de.xelerity.geolessi.preferences.Preferences;
import de.xelerity.geolessi.srv.ServiceProvider;
import de.xelerity.geolessi.srv.impl.poi.types.meinestadt.MSPOI;
import de.xelerity.geolessi.srv.mixed.URLGenerator;
import de.xelerity.geolessi.srv.mixed.WSCallerI;

public class TEST {

	private void RUN() throws Exception {
		String URL = "http://stadtplan.meinestadt.de/xml/java-service/poi?output=json&context=poi-service&centerX=9.181&centerY=48.777&radiusX=0.114&radiusY=0.067&amount=10000&category=4&clusterRadius=0.25&maxClusterItems=36";

		URLGenerator urlGenerator = new URLGenerator("stadtplan.meinestadt.de", "xml/java-service/poi");

		System.out.println(urlGenerator);

		urlGenerator.addParameter("output", "json");
		urlGenerator.addParameter("context", "poi-service");
		urlGenerator.addParameter("centerX", "9.181");
		urlGenerator.addParameter("centerY", "48.777");
		urlGenerator.addParameter("radiusX", "0.114");
		urlGenerator.addParameter("radiusY", "0.067");
		urlGenerator.addParameter("amount", "1000");
		urlGenerator.addParameter("category", "4");
		urlGenerator.addParameter("clusterRadius", "0.25");
		urlGenerator.addParameter("maxClusterItems", "36");

		System.out.println(urlGenerator);

		URL = urlGenerator.getURL();

		// http://jsongen.byingtondesign.com/

		WSCallerI wsCaller2 = ServiceProvider.getWSCaller();

		if (Preferences.useProxy) {
			wsCaller2.addProperty("PROXYHOST", Preferences.Proxy);
			wsCaller2.addProperty("PROXYPORT", Preferences.ProxyPort + "");
		}

		byte[] callResB = wsCaller2.call(URL);

		String callRes = new String(callResB, "UTF-8");

		System.out.println(callRes);

		ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally

		MSPOI poi = mapper.readValue(callRes, MSPOI.class);

		System.out.println(poi);

	}

	public static void main(String[] args) {

		try {
			new TEST().RUN();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
